import 'package:dio/dio.dart';
import 'package:practise/arch/log/log.dart';
import 'package:practise/arch/utils/time_util.dart';

class HttpLogInterceptor implements Interceptor {

  static const _TAG = "HttpLog";

  @override
  Future onError(DioError err) async {
    Logger.log(_TAG, "Request Error ${err.message}");
    Logger.log(_TAG, "-----------------------------------" * 3);
    return err;
  }

  @override
  Future onRequest(RequestOptions options) async {
    Logger.log(_TAG, "Request start  : ${TimeUtils.getCurrentTimeStamp()},"
        " method : ${options.method},"
        " path : ${options.path}");
    Logger.log(_TAG, "------------------------------------" * 3);
    return options;
  }

  @override
  Future onResponse(Response<dynamic> response) async {
    Logger.log(_TAG, "Request finish : ${TimeUtils.getCurrentTimeStamp()},"
        " method : ${response.request.method},"
        " path : ${response.request.path},"
        " code : ${response.statusCode}"
        " headers : ${response.request.headers},\n"
        " params : ${response.request.queryParameters}\n"
        " body : ${response.data}");
    Logger.log(_TAG, "-----------------------------------" * 3);
    return response;
  }



}